//    Copyright (C) Clear Office.  All rights reserved.
using System.Collections.Generic;
using Office.Core.Serialization;

namespace Office.Spreadsheet.PivotTable
{
    class RowColumnItem : IOfficeXmlSerializable
    {
        private ItemType _t;
        private int _r;
        private int _i;
        private List<RowColumnIndex> _x = new List<RowColumnIndex>();

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("i"))
            {
                _t = c.GetOptionalEnum("t", ItemType.Data);
                _r = c.GetOptionalInteger("r", 0);
                _i = c.GetOptionalInteger("i", 0);
                _x.Clear();
                _x.AddRange(c.ReadOptionalWhile<RowColumnIndex>("x"));
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("i"))
            {
                c.SetOptionalEnum("t", _t, ItemType.Data);
                c.SetOptionalInteger("r", _r, 0);
                c.SetOptionalInteger("i", _i, 0);
                c.WriteElements(_x);
            }
        }
    }
}